home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / B_YOOHOO.C < prev    next >
Text File  |  1988-11-29  |  16KB  |  504 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*               The Opus Computer-Based Conversation System                */
  3. /*       (c) Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  4. /*                                                                          */
  5. /*                   YOOHOO is a trademark of Wynn Wagner III               */
  6. /*                                                                          */
  7. /*                            YOOHOO-YOOHOO/2U2 is                          */
  8. /*           Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  9. /*                                                                          */
  10. /*                 This module was written by W.Wagner III                  */
  11. /*                with modifications done by Vince Perriello                */
  12. /*                and more modifications done by Bob Hartman                */
  13. /*                                                                          */
  14. /*                                                                          */
  15. /*                     BinkleyTerm "YooHoo" Processor                       */
  16. /*                                                                          */
  17. /*                                                                          */
  18. /*  This module is a very simple FOSSIL-based terminal emulator. It is      */
  19. /*  provided for your information only.  You will find routines that need   */
  20. /*  to be coded and identifiers to be resolved. It has been previously      */
  21. /*  known as "OpusLink" and "OConnect". The use of the name "BinkleyTerm"   */
  22. /*  does not preclude the possibility that another "OpusLink" or "OConnect" */
  23. /*  could be released.                                                      */
  24. /*                                                                          */
  25. /*  There is absolutely no guarantee that anything here will work.  If you  */
  26. /*  break this routine, you own both pieces.                                */
  27. /*                                                                          */
  28. /*  USAGE:  You may use this material in any program with no obligation     */
  29. /*          as long as there is no charge for your program.  For more       */
  30. /*          information about commercial use, contact the "OPUSinfo HERE"   */
  31. /*          BBS (124/111).                                                  */
  32. /*                                                                          */
  33. /*                                                                          */
  34. /*--------------------------------------------------------------------------*/
  35.  
  36. #include <stdio.h>
  37. #include <signal.h>
  38. #include <ctype.h>
  39. #include <conio.h>
  40.  
  41. #define WAZOO_SECTION
  42. #define MATRIX_SECTION
  43. #define isBITBRAIN 0x1b
  44.  
  45. #include "com.h"
  46. #include "xfer.h"
  47.  
  48. extern char   *CRC_msg;
  49. extern char   *SHRT_msg;
  50. extern char   *FUBAR_msg;
  51. extern char   *TIME_msg;
  52. extern char   *IDUNNO_msg;
  53. extern char   *KBD_msg;
  54. extern char   *local_CEOL;
  55.  
  56. extern int un_attended;
  57. extern int fullscreen;
  58.  
  59. char   no_zapzed = 0;
  60. int    hup       = 0;
  61.  
  62.  
  63. int   send_YOOHOO(int);
  64. int   get_YOOHOO();
  65. int   send_Hello();
  66.  
  67.  
  68.  
  69. /*--------------------------------------------------------------------------*/
  70. /* SEND YOOHOO                                                              */
  71. /*--------------------------------------------------------------------------*/
  72. int send_YOOHOO(instigator)
  73.    int instigator;
  74.    begin
  75.       char *sptr  = NULL;
  76.  
  77.       if (un_attended && fullscreen)
  78.          {
  79.          gotoxy (0, 16);
  80.          }
  81.       set_xy( "YooHoo " );
  82.       if (!send_Hello()) 
  83.          begin
  84.             sptr  = "No Send";
  85.             goto nope;
  86.          end
  87.  
  88.       if (instigator)
  89.          begin
  90.             if (TIMED_READ(12)==YOOHOO) return get_YOOHOO(0);
  91.  
  92.             status_line("!No YOOHOO/2U2");
  93.             set_xy(NULL);
  94.          end
  95.       sptr  = IDUNNO_msg;
  96.  
  97. nope:
  98.       if (sptr) message(sptr);
  99.       return 0;
  100.  
  101.    end
  102.  
  103.  
  104.  
  105.  
  106. /*--------------------------------------------------------------------------*/
  107. /* TRANSMIT HELLO PACKET                                                    */
  108. /*--------------------------------------------------------------------------*/
  109. int send_Hello()
  110.    begin
  111.       int            i;
  112.       struct _Hello  Hello;
  113.       byte          *sptr;
  114.       word           crc;
  115.       word           num_errs = 0;
  116.  
  117.  
  118.       /*--------------------------------------------------------------------*/
  119.       /* Setup HELLO structure                                              */
  120.       /*--------------------------------------------------------------------*/
  121.       memset( (char *)&Hello, 0, sizeof(struct _Hello) );
  122.  
  123.       Hello.signal         = 'o';
  124.       Hello.hello_version  =  1;
  125.  
  126.       Hello.product        = isBITBRAIN;
  127.       Hello.product_maj    = BINK_MAJVERSION;
  128.       Hello.product_min    = BINK_MINVERSION;
  129.  
  130.       strncpy( Hello.my_name, ctl.system_name, 58 );
  131.       Hello.my_name[59]    = '\0';
  132.  
  133.       strncpy( Hello.sysop, ctl.sysop, 19 );
  134.       Hello.sysop[19]      = '\0';
  135.  
  136.       Hello.my_zone        = ctl.our_zone;
  137.       Hello.my_net         = ctl.alias[0].net;
  138.       Hello.my_node        = ctl.alias[0].node;
  139.  
  140.       Hello.capabilities   = (no_zapzed)?Y_DIETIFNA:Y_DIETIFNA|ZED_ZAPPER;
  141.  
  142.       if (n_getpassword( remote_net, remote_node ))
  143.          begin
  144.             strncpy( Hello.my_password, remote_password, 7 );
  145.          end
  146.       else
  147.          begin
  148.             Hello.my_password[0] = '\0';
  149.          end
  150.       Hello.my_password[6] = '\0';
  151.  
  152.       if (ctl.matrix_mask&TAKE_REQ)
  153.          Hello.capabilities |= WZ_FREQ;
  154.  
  155.  
  156.  
  157.  
  158.       /*--------------------------------------------------------------------*/
  159.       /* Disable handshaking and ^C/^K handling                             */
  160.       /*--------------------------------------------------------------------*/
  161.       XON_DISABLE();
  162.       brk_disable();
  163.  
  164.       /*--------------------------------------------------------------------*/
  165.       /* Send the packet.                                                   */
  166.       /* Load outbound buffer quickly, and get modem busy sending.          */
  167.       /*--------------------------------------------------------------------*/
  168.  
  169. send:
  170.  
  171.       SENDBYTE( 0x1f );
  172.  
  173.       if ( (num_errs++) > 10 )
  174.          begin
  175.              message(FUBAR_msg);
  176.             return 0;
  177.          end
  178.  
  179.       sptr  = (char *)(&Hello);
  180.       SENDCHARS (sptr, 128, 1);
  181. /*
  182.       for(i=0; i<128; i++ ) SENDBYTE( sptr[i] );
  183. */
  184.  
  185.  
  186.       /*--------------------------------------------------------------------*/
  187.       /* Clear inbound ring buffer                                          */
  188.       /*--------------------------------------------------------------------*/
  189.       CLEAR_INBOUND();
  190.  
  191.  
  192.       /*--------------------------------------------------------------------*/
  193.       /* Calculate CRC while modem is sending its buffer                    */
  194.       /*--------------------------------------------------------------------*/
  195.       for(crc=i=0;i<128;i++)
  196.          begin
  197.             crc = xcrc(crc,(byte )sptr[i]);
  198.          end
  199.  
  200.       CLEAR_INBOUND();
  201.  
  202.       SENDBYTE( crc>>8   );
  203.       SENDBYTE( crc&0xff );
  204.  
  205.  
  206.       while(1)
  207.          switch( i=TIMED_READ(17) )
  208.             begin
  209.                 case ACK :
  210.                            return 1;
  211.    
  212.                case '?' :  message("drats");
  213.                            goto send;
  214.  
  215.                case ENQ :  break;
  216.    
  217.                default  :  if (i>0) /* Could just be line noise */
  218.                               begin
  219.                                  cprintf("[%x] ",i);
  220.                                  break;
  221.                               end
  222.                            /* If we didn't get anything, that is bad */
  223.                            return 0;
  224.             end
  225.  
  226.    end /* Send Hello */
  227.  
  228.  
  229.  
  230.  
  231. /*--------------------------------------------------------------------------*/
  232. /* GET YOOHOO                                                               */
  233. /*--------------------------------------------------------------------------*/
  234. int get_YOOHOO( plan_to_send_too )
  235.    int plan_to_send_too;
  236.    begin
  237.       int            i;
  238.       int            c;
  239.       struct _Hello  Hello;
  240.       byte          *sptr;
  241.       byte           num_errs = 0;
  242.       int            timer_val;
  243.       word           crc;
  244.       word           lsb;
  245.       word           msb;
  246.       long           t,timerset();
  247.  
  248.       /* To get here, Opus has already read the YOOHOO */
  249.       hup = 0;
  250.       sptr           = NULL;
  251.       if (remote_capabilities>0)
  252.          begin
  253.             return 1;
  254.          end
  255.  
  256.       /*--------------------------------------------------------------------*/
  257.       /* Clean up any mess that may be around                               */
  258.       /*--------------------------------------------------------------------*/
  259.       CLEAR_OUTBOUND();
  260.       CLEAR_INBOUND();
  261.       XON_DISABLE();
  262.       brk_disable();
  263.  
  264.  
  265.       /*--------------------------------------------------------------------*/
  266.       /* Get the Hello structure                                            */
  267.       /*--------------------------------------------------------------------*/
  268.  
  269.       SENDBYTE(ENQ); /* Let the other system know we're curious. */
  270.       if (un_attended && fullscreen)
  271.          {
  272.          gotoxy (0, 17);
  273.          }
  274.       set_xy("YooHoo/2U2 ");
  275.  
  276. recv:
  277.       i  = 0;
  278.       while(1)
  279.          begin
  280.  
  281.             if (sptr)
  282.                begin
  283.                   message(sptr);
  284.                   sptr  = NULL;
  285.                end
  286.  
  287.             if (((KEYPRESS()) and (READKB()==27)))
  288.                begin
  289.                   sptr  = KBD_msg;
  290.                   goto failed;
  291.                end
  292.  
  293.             if ((c=TIMED_READ(12)) == 0x1f) goto loop;
  294.  
  295.             if (!CARRIER)
  296.                begin
  297.                    sptr  = CARRIER_msg;
  298.                   goto failed;
  299.                end
  300.  
  301.             if (c<0)
  302.                begin
  303.                   if ((i++) > 7)
  304.                      begin
  305.                         sptr  = TIME_msg;
  306.                         goto failed;
  307.                      end
  308.                end
  309.             else
  310.                begin
  311.                   if (i>1) sptr  = "Scratching head";
  312.                   else
  313.                      begin
  314.                         t  = timerset(1000);
  315.                         while( (PEEKBYTE()>=0)&&(CARRIER)&&(!timeup(t)) )
  316.                            if (MODEM_IN()==0x1f) goto loop;
  317.                         i  = 1;
  318.                      end
  319.                   CLEAR_INBOUND();
  320.                   SENDBYTE(ENQ);
  321.                end
  322.  
  323.          end /* while */
  324.  
  325.  
  326. loop:
  327.  
  328.       sptr  = (char *)(&Hello);
  329.       for(i=0; i<128; i++ )
  330.          begin
  331.             if ( (c=TIMED_READ(17)) < 0 )
  332.                begin
  333.                   sptr  = TIME_msg;
  334.                   goto failed;
  335.                end
  336.             else sptr[i] = c;
  337.          end
  338.  
  339.  
  340.       /*--------------------------------------------------------------------*/
  341.       /* Calculate CRC                                                      */
  342.       /*--------------------------------------------------------------------*/
  343.       begin
  344.          for(crc=i=0;i<128;i++)
  345.             begin
  346.                crc = xcrc(crc,(byte )sptr[i]);
  347.             end
  348.  
  349.          if (!CARRIER)
  350.             begin
  351.                sptr  = CARRIER_msg;
  352.                goto failed;
  353.             end
  354.          else sptr   = NULL;
  355.  
  356.          msb    = TIMED_READ(3);
  357.          lsb    = TIMED_READ(3);
  358.  
  359.          if ((lsb<0)||(msb<0))
  360.             begin
  361.                sptr = SHRT_msg;
  362.                goto err;
  363.             end
  364.          else if ( ((msb<<8)|lsb) != crc )
  365.             begin
  366.                sptr = CRC_msg;
  367.  
  368. err:           if ( (num_errs++) > 10 )
  369.                   begin
  370.                       sptr  = FUBAR_msg;
  371.                      goto failed;
  372.                   end
  373.  
  374.                CLEAR_INBOUND();
  375.                SENDBYTE('?');
  376.                goto recv;
  377.  
  378.             end
  379.       end
  380.  
  381.  
  382.       Hello.my_name[42]    = '\0';
  383.       Hello.sysop[19]      = '\0';
  384.       opus_maj             = Hello.product_maj;
  385.       opus_min             = Hello.product_min;
  386.       remote_zone          = Hello.my_zone;
  387.       remote_net           = Hello.my_net;
  388.       remote_node          = Hello.my_node;
  389.       remote_point         = Hello.my_point;
  390.       remote_capabilities  = (Hello.capabilities)|Y_DIETIFNA;
  391.  
  392.  
  393.       status_line("*%s (%u:%u/%u.%u)",
  394.                     Hello.my_name,
  395.                     remote_zone,
  396.                     remote_net,
  397.                     remote_node,
  398.                     remote_point);
  399.  
  400.        switch (Hello.product)
  401.          {
  402.          case isBITBRAIN:
  403.             status_line ("*Remote Uses BinkleyTerm Version %d.%d",
  404.                Hello.product_maj, Hello.product_min);
  405.             break;
  406.          case isOPUS:
  407.             status_line ("*Remote Uses Opus Version %d.%d", Hello.product_maj,
  408.                (Hello.product_min == 48) ? 0 : Hello.product_min);
  409.             break;
  410.          case isFIDO:
  411.             status_line ("*Remote Uses Fido-Something Version %d.%d",
  412.                Hello.product_maj, Hello.product_min);
  413.             break;
  414.          case isSPARK:
  415.             status_line ("*Remote Uses Spark-Something Version %d.%d",
  416.                Hello.product_maj, Hello.product_min);
  417.             break;
  418.          case isSEA:
  419.             status_line ("*Remote Uses SEA-Something Version %d.%d",
  420.                Hello.product_maj, Hello.product_min);
  421.             break;
  422.          case isHENK:
  423.             status_line ("*Remote Uses Dutchie-Something Version %d.%d",
  424.                Hello.product_maj, Hello.product_min);
  425.             break;
  426.          case isTABBIE:
  427.             status_line ("*Remote Uses Tabbie-Something Version %d.%d",
  428.                Hello.product_maj, Hello.product_min);
  429.             break;
  430.          default:
  431.             status_line ("*Remote Uses Program '%02x' Version %d.%d",
  432.                Hello.product, Hello.product_maj, Hello.product_min);
  433.             break;
  434.          }
  435.  
  436.       if (Hello.sysop[0])
  437.          begin
  438.             Hello.sysop[19] = '\0';
  439.             strcpy( remote_sysop, Hello.sysop );
  440.             status_line( ":Sysop: %s", remote_sysop );
  441.          end
  442.  
  443.       if (un_attended && fullscreen)
  444.          begin
  445.             gotoxy (0,19);
  446.          end
  447.  
  448.       if (n_getpassword( Hello.my_net, Hello.my_node ))
  449.          begin
  450.             if (n_password(remote_password,Hello.my_password))
  451.                begin
  452.                   goto failed;
  453.                end
  454.          end
  455.  
  456.       CLEAR_INBOUND();
  457.  
  458.       SENDBYTE(ACK);
  459.       SENDBYTE(YOOHOO);
  460.  
  461.  
  462.       if (plan_to_send_too)
  463.          begin
  464.  
  465.             for(i=0; (CARRIER) and (i<10); i++)
  466.                begin
  467.                   if ((c=TIMED_READ(5))==ENQ)
  468.                      begin
  469.                         n_getpassword(Hello.my_net,Hello.my_node);
  470.                         return send_Hello()? 1: (b_init(),0);
  471.                      end
  472.                   else
  473.                      begin
  474.                         if (c>0)
  475.                            begin
  476.                               message(NULL);
  477.                               cprintf("[%x] ",c);
  478.                               CLEAR_INBOUND();
  479.                            end
  480.                         SENDBYTE(YOOHOO);
  481.                      end
  482.                end
  483.  
  484.             sptr  = FUBAR_msg;
  485.             goto failed;
  486.  
  487.          end
  488.  
  489.       return 1;
  490.  
  491. failed:
  492.  
  493.       hup = 1;
  494.       message(sptr);
  495.       b_init();
  496.       return 0;
  497.  
  498.    end /* get_yoohoo */
  499.  
  500.  
  501.  
  502. /* END OF FILE: n_yoohoo.c */
  503.  
  504.